package com.zzxx.mapper;

import com.zzxx.pojo.Orders;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.mapping.FetchType;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface OrderMapper {
	@Results(id = "orders-product", value = {
	@Result(id = true, column = "id", property = "id"),
	@Result(column = "productId", property = "product",one = @One(select = "com.zzxx.mapper.ProductMapper.findById",fetchType = FetchType.LAZY))
	})
	@Select("select * from orders")
	public List<Orders> findAll();

	@Results(id = "orders-product-traveller-member", value = {
	@Result(id = true, column = "id", property = "id"),
	@Result(column = "productId", property = "product",one = @One(select = "com.zzxx.mapper.ProductMapper.findById",fetchType = FetchType.LAZY)),
	@Result(column = "id", property = "travellers", many = @Many(select = "com.zzxx.mapper.TravellerMapper.findByOrderId", fetchType = FetchType.LAZY)),
	@Result(column = "memberId", property = "member",one = @One(select = "com.zzxx.mapper.MemberMapper.findById", fetchType = FetchType.LAZY))
	})
	@Select("select * from orders where id = #{id}")
	Orders findById(String id);

	@Update("update orders set orderTime = #{orderTime}, peopleCount = #{peopleCount}, " +
	"orderDesc = #{orderDesc}, payType = #{payType}, orderStatus = #{orderStatus} where id = #{id}")
	void update(Orders order);
}
